﻿

#region Using directives
using System;
using InvoiceChecking.Data;
using InvoiceChecking.Entities;
using InvoiceChecking.Web.UI;
#endregion

public partial class Admin_ReturnInvoice : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        FormUtil.SetPageIndex(GridView1, "page");
    }

    protected void btn_Add_Click(object sender, EventArgs e)
    {
        if (tb_InvoiceNumber.Text.Length == 10)
        {
            DailyTrans dailyTrans = DataRepository.DailyTransProvider.GetByVatNumberCmsNumber(tb_InvoiceNumber.Text,
                                                                                                        tb_InvoiceNumber.Text.Substring(5));
            if (dailyTrans == null)
            {
                DataRepository.DailyTransProvider.CreateInvoice(tb_InvoiceNumber.Text);
                dailyTrans = DataRepository.DailyTransProvider.GetByVatNumberCmsNumber(tb_InvoiceNumber.Text,
                                                                                                  tb_InvoiceNumber.Text.
                                                                                                      Substring(5));
            }
            if (dailyTrans != null)
            {
                dailyTrans.Returned = true;
                dailyTrans.Received = false;
                dailyTrans.ReceivedDate = null;
                dailyTrans.ReturnedDate = DateTime.Now;
                dailyTrans.Remark = tb_Reason.Text;
                DataRepository.DailyTransProvider.Update(dailyTrans);
                tb_InvoiceNumber.Text = "";
                tb_Reason.Text = "";
                GridView1.DataBind();
            }
        }
        tb_InvoiceNumber.Focus();
    }
    protected void btn_Print_Click(object sender, EventArgs e)
    {
        Response.Redirect("ReportReturn.aspx",true);
    }
}


